<%--
  Created by IntelliJ IDEA.
  User: lq
  Date: 2016/12/14/0014
  Time: 14:31
  To change this template use File | Settings | File Templates.
--%>
<%@page import="com.rivercloud.entity.UserVo"%>
<%@page import="java.util.List"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String basePath1 = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
						+ path;
	
	String url = basePath1  + request.getServletPath()+ "?" + (request.getQueryString());
	
	request.setAttribute("basePath", basePath);
	request.setAttribute("url", url);
	
	/* alan_18.2.6_start_获取页面路径 */
	
	String get_basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
	+ path ;
	String get_url_tmp = get_basePath  + request.getServletPath()+ "?" + (request.getQueryString());
	String get_url = get_url_tmp.replace("/WEB-INF/jsp","/excel").replace(".jsp", "");
	/* alan_18.2.6_end */

%>
<html>
<head>
<base href="<%=basePath%>">
<title>文件列表</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="${base}/css/jquery.searchableSelect.css">
<script type="text/javascript" src="${base}/js/jquery-3.1.0.js"></script>
<script type="text/javascript" src="${base}/js/bootstrap.js"></script>
<script type="text/javascript"
	src="${base}/js/jquery.searchableSelect.js"></script>
<script src="${base}/js/plugins/layer/layer.min.js"></script>
	

</head>
<body>
	<div class="container">
		<jsp:include page="${path}/menu.jsp"></jsp:include>
		<div style="margin-left: 20px;margin-bottom: 10px; color: grey">当前位置：表格管理 > 未完成表格 > ${tableName }</div>
		
		<button type="button" class="btn btn-primary" id="tableName"  disabled="disabled">${tableName}</button>
		<br>
		
		<div style="overflow-x: scroll; width: 100%; white-space: nowrap;">
			<div style="overflow-y: scroll; white-space: nowrap; height: 420px;">
				<!-- alan_18.3.1_start_update_style -->
				<!-- <table id="table"  class="table table-condensed table table-bordered" -->
				<table id="table"  class="table table-striped table-bordered table-hover dataTables-example"
					style="width: 100%; table-layout: fixed; margin-top: 50px"
					align="center" id="table">
					<tbody id="tbody">
						<tr class="th"   style="height: 40px;">
						
							<c:forEach items="${title}" var="ti"   varStatus="index">
								<%-- <td style="background-color: #EC971F; width: 150px"><a>${ti}</a></td> --%>
								<td  class="td1" onclick="get(this)"  style="width: 120px;border:1px solid #88ADA6;height: 40px;background-color:#9BCD9B"><input  type="button"
									style="background-color:#9BCD9B; border: none; height: 100%; font-size: 8px; width: 100%; word-wrap: break-word;" 
									value="${ti.toString().trim()}" /></td>
							</c:forEach>
						</tr>
			
						
						<c:forEach items="${data}" var="ds" varStatus="i">
							<tr class="tr${i.index }" style="height: 30px;">
							
							<c:set var="a" value="0"></c:set>
							<c:forEach items="${tableColList}" var="tableCol" varStatus="j" >
								<c:if test="${tableCol.colType==0}">
								
								<td class="td" onclick="get(this)"  style="width: 5%;height:40px;border:1px solid #88ADA6;" ><input
										type="text" onchange="textbox()" readonly="readonly" editor="${tableRowList[i.count-1].userId}" colEditor="${tableCol.colEditor}"
										style="border: none; height: 100%; font-size: 14px; width: 100%; word-wrap: break-word;background-color: #CCCCCC;" 
										value='${ds[a].toString().trim()}'></td>
										
								</c:if>
								<c:set var="avv" scope="request"  value="${i.index}"></c:set>
								<c:if test="${tableCol.colType==1}">
									<c:set value="${ fn:split(tableCol.defVal, '||') }" var="val" />
									
									<c:set var = "x" value = "${ds[a].toString().trim()}"></c:set>
									<c:out value = "${aa}"></c:out>
									
									<td class="td" onclick="get(this)"  style="width: 5%;height:auto;border:1px solid #88ADA6;"><select  id="ssss${avv}"
										style="width: 100%; height: 30px;" onchange="dropDown(this)">
											<c:forEach items="${val}" var="va"  >
											
												<c:choose>
												
												
												<c:when test="${x != (fn:substring(va,0,fn:indexOf(va,'#'))).trim()}">
													<option  class="${fn:substring(va,fn:indexOf(va,'#'),fn:length(va))}" >${fn:substring(va,0,fn:indexOf(va,'#'))}</option>
												
												</c:when>
												
												
												<c:otherwise>
													<option  class="${fn:substring(va,fn:indexOf(va,'#'),fn:length(va))}"    id="${fn:substring(va,fn:indexOf(va,'#'),fn:length(va))}" selected="selected">${fn:substring(va,0,fn:indexOf(va,'#'))}</option>
												</c:otherwise>
												</c:choose> 
										
											</c:forEach>
													<script type="text/javascript">
								      var ooo=document.getElementById("ssss"+'${avv}');
								     var index=ooo.selectedIndex; //序号，取当前选中选项的序号
									 var bg= ooo.options[index].id;
								     ooo.style.background=bg; 
									</script>
									</select></td>
									
									
									
									
								</c:if>
								<c:set var="a" value="${a+1}"></c:set>
							</c:forEach>
							
						</tr>
						
					</c:forEach>
					</tbody>
				</table>
			</div>
			<c:if test="${table.userId == user.id}">
				<!-- <button type="button" class="btn btn-primary" onclick="getUrl()">获取地址</button> -->
				
				<!-- alan_18.2.6_start -->
				
				<!-- 获取地址 -->
			<input id="copy-num" class="form-control" type="text" value="<%=get_url%>" style="max-width:100px;display:inline-block;color: #999; margin-top:12px">
                <button onClick="urlCopy()" type="button" class="btn btn-primary">获取地址</button>
				<!-- alan_18.2.6_end -->
				
				<button type="button" class="btn btn-primary" onclick="hb()">合并</button>
				<button type="button" class="btn btn-primary" onclick="resolution()">拆分</button>
				<button class="btn btn-primary" data-toggle="modal" data-target="#colModal">加列</button>
			<button class="btn btn-primary" data-toggle="modal" data-target="#rowModal">加行</button>
				
			<c:if test="${table.tableStatus == 0}">
				<button type="button" class="btn btn-primary" onclick="setFinish(${project.id},${tableId })">标记为已完成</button>
			
			</c:if>
			</c:if>
			
			<c:if test="${existUserTable==null}">
					<button type="button" class="btn btn-primary"
					onclick="collection(${user.id},${tableId })">添加关注</button>
				</c:if>
				<c:if test="${existUserTable != null}">
					<button type="button" class="btn btn-primary"
					onclick="deleteCollection(${user.id},${tableId })">取消关注</button>
				</c:if>
			
			
			
										<c:set scope="page" value="manager" var="pagein"></c:set>
										<!-- 为每个要判断的按钮或者功能定义一个变量，对应数据库后台的权限表中的keyword字段 -->
							 <% 
								  String pageDelete=(String)pageContext.getAttribute("pagein");
								  //然后改变这里取出来
								  System.out.print(pageDelete);
								  UserVo userVo=(UserVo)session.getAttribute("userVo");
								 
								  if(userVo != null){
								  String keyword=userVo.getrKeyword();
								 
								 String [] keywords=keyword.split(",");
									  Boolean flag=false;
									 
										  flag=keyword.equals(pageDelete);//这里改变，最后就能实现了
									  
									  System.out.println(userVo.getuName()+"权限为："+flag);
									   if(flag){
								%>
			<button class="btn btn-primary" data-toggle="modal"
				data-target="#myModal">存为模板</button>
			<!--  定义模态框触发器，此处为按钮触发  -->
			
				<%
									   }
								  }
				%>
			
			<form method="post" action="${pageContext.request.contextPath}/tpl/toTemplate?tableId=${tableId}&userId=${user.id}" class="form-horizontal" role="form"
				id="myForm" onsubmit="return ">
				<div class="modal fade" id="myModal" role="dialog" tabindex=-1
					aria-labelledby="myModalLabel" aria-hidden="true">
					<!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
					<div class="modal-dialog">
						<!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
						<div class="modal-content">
							<!--  显示模态框白色背景，所有内容都写在这个div里面  -->

							<div class="btn-info modal-header">
								<!--  模态框标题  -->
								<button type="button" class="close" data-dismiss="modal">&times;</button>
								<!--  关闭按钮  -->
								<h4>存为模板</h4>
								<!--  标题内容  -->
							</div>

							<div class="modal-body">
								<!--  模态框内容，我在此处添加一个表单 -->
								<form class="form-horizontal" role="form">
									<div class="form-group">
										<label for="templateName" class="col-sm-3 control-label">模板名称：</label>
										<div class="col-sm-6">
											<input type="text" id="templateName" name="templateName"
												class="form-control well" placeholder="请输入模板名" />
												<span id="s1"></span>
										</div>
									</div>
									
								</form>
							</div>

							<div class="modal-footer">
								<!--  模态框底部样式，一般是提交或者确定按钮 -->
								<button type="submit" class="btn btn-info">确定</button>
								<button type="button" class="btn btn-default"
									data-dismiss="modal">取消</button>
							</div>

						</div>
						<!-- /.modal-content -->
					</div>
				</div>
				<!-- /.modal -->
			</form>
			
			<form method="post" action="" class="form-horizontal" role="form"
							id="colEditorForm" onsubmit="return ">
							<div class="modal fade" id="colModal" role="dialog" tabindex=-1
								aria-labelledby="myModalLabel" aria-hidden="true">
								<!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
								<div class="modal-dialog">
									<!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
									<div class="modal-content">
										<!--  显示模态框白色背景，所有内容都写在这个div里面  -->

										<div class="btn-info modal-header">
											<!--  模态框标题  -->
											<button type="button" class="close" data-dismiss="modal">&times;</button>
											<!--  关闭按钮  -->
											<h4>密码修改</h4>
											<!--  标题内容  -->
										</div>

										<div class="modal-body">
											<!--  模态框内容，我在此处添加一个表单 -->
											<form class="form-horizontal" role="form">
												<div class="form-group">
													<label for="colName" class="col-sm-3 control-label">列名：</label>
													<div class="col-sm-5">
														<input type="text" id="colName" name="colName"
															class="form-control well"  placeholder="请输入列名"   /> 
													</div>
													<span id="s1"></span>
												</div>
												<div class="form-group">
													<label for="memberName1" class="col-sm-3 control-label">该列编辑人：</label>
													<div class="col-sm-5">
														<select id="memberName1"    name="memberName1" class="se" >
															<option value="">请选择或者输入成员姓名</option>
															<c:forEach items="${users}" var="user">
																<option value="${user.id }">${user.name }</option>
															</c:forEach>
														</select>
													</div>
												</div>
												
											</form>
										</div>

										<div class="modal-footer">
											<!--  模态框底部样式，一般是提交或者确定按钮 -->
											<input type="button"   data-dismiss="modal"  class="btn btn-info" onclick="addEditorCol()" id="sChange" value="确定">
											<button type="button" class="btn btn-default"
												data-dismiss="modal">取消</button>
										</div>

									</div>
									<!-- /.modal-content -->
								</div>
							</div>
							<!-- /.modal -->
						</form>
			<form method="post" action="" class="form-horizontal" role="form"
							id="rowEditorForm" onsubmit="return ">
							<div class="modal fade" id="rowModal" role="dialog" tabindex=-1
								aria-labelledby="myModalLabel" aria-hidden="true">
								<!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
								<div class="modal-dialog">
									<!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
									<div class="modal-content">
										<!--  显示模态框白色背景，所有内容都写在这个div里面  -->

										<div class="btn-info modal-header">
											<!--  模态框标题  -->
											<button type="button" class="close" data-dismiss="modal">&times;</button>
											<!--  关闭按钮  -->
											<h4>设置行编辑人</h4>
											<!--  标题内容  -->
										</div>

										<div class="modal-body">
											<!--  模态框内容，我在此处添加一个表单 -->
											<form class="form-horizontal" role="form">
												
												<div class="form-group">
													<label for="rowEditorName" class="col-sm-3 control-label">该行编辑人：</label>
													<div class="col-sm-5">
														<select id="rowEditorName"    name="rowEditorName" class="se" >
															<option value="">请选择或者输入成员姓名</option>
															<c:forEach items="${users}" var="user">
																<option value="${user.id }">${user.name }</option>
															</c:forEach>
														</select>
													</div>
												</div>
												
											</form>
										</div>

										<div class="modal-footer">
											<!--  模态框底部样式，一般是提交或者确定按钮 -->
											<input type="button"   data-dismiss="modal"  class="btn btn-info" onclick="addEditorRow()" id="sChange" value="确定">
											<button type="button" class="btn btn-default"
												data-dismiss="modal">取消</button>
										</div>

									</div>
									<!-- /.modal-content -->
								</div>
							</div>
							<!-- /.modal -->
						</form>
					
			
		</div>
	</div>
</body>

<script type="text/javascript">

		
		var el = window.document.body;//声明一个变量，默认值为body
		
		window.document.body.onclick = function(event){
			
			
			  el = event.target;//鼠标每经过一个元素，就把该元素赋值给变量el
			
			  console.log('当前鼠标在', el, '元素上');//在控制台中打印该变量
			
				colObj = event.target;
				
		}

		$('#memberName1').searchableSelect();
		$('#rowEditorName').searchableSelect();
	$(function(){
		
		var rows = table.rows.length;
		
		var cells = table.rows.item(0).cells.length;
		
		var userId = ${user.id};
		var creatorId = ${table.userId};
		
		var tableId = ${table.id};
		
		
		for (var i = 0; i < rows; i++) {
		
			for (var j = 0; j < cells; j++) {
				var obj = $(table.rows.item(i).cells.item(j).childNodes[0]);
				
				var td_input = obj.attr("editor");
				var td_input2 = obj.attr("colEditor");
				if(obj[0].tagName == 'INPUT'){
					
					if(userId == td_input || userId == creatorId || userId == td_input2 || '${user.name}' == '${project.managerName}' ){
						$(obj).removeAttr("readonly");
						if(i != 0){
							$(obj).css("background-color", "#FFFFFF");
						}
						
						
					}
				}
				
				
			}
			
		}
		//加载列合并信息
		$.ajax({
			url : "${base}/table/findMergeByTableId",
			data : {
			
				"tableId" : tableId
			},
			type : "POST",
			success : function(data) {
				var a = eval(data);
				
				for (var j = 0; j < a.length; j++) {
					var td = table.rows.item(a[j].rowNum).cells.item(a[j].colNum);
					$(td).attr("colspan",a[j].colspan);
					$(td).css("width",parseInt(a[j].colspan*120)+"px");
					for(var i=(a[j].colNum+a[j].colspan);i>a[j].colNum+1;i--){
						$(table.rows[a[j].rowNum].cells[i-1]).hide(); 
					
					}
				}
				
			},
			async : true,
			cache : false
		});  
		//加载行合并信息
		$.ajax({
			url : "${base}/table/findMergeRowByTableId",
			data : {
			
				"tableId" : tableId
			},
			type : "POST",
			success : function(data) {
				var mergeRow = eval(data);
				
				for (var j = 0; j < mergeRow.length; j++) {
					var td = table.rows.item(mergeRow[j].rowNum).cells.item(mergeRow[j].colNum);
					$(td).attr("rowspan",mergeRow[j].rowspan);
					for(var i=(mergeRow[j].rowNum+mergeRow[j].rowspan);i>mergeRow[j].rowNum+1;i--){
						
						$(table.rows[i-1].cells[mergeRow[j].colNum]).hide();
						
					}
				}
				
			},
			async : true,
			cache : false
		});  
	}); 

	/* 	function seted(obj){
			var td_input = $(obj).attr("editor");
			var userId = ${user.id};
			var creatorId = ${table.userId};
			
			
			
			if(userId == td_input || userId == creatorId){
				$(obj).removeAttr("readonly");
				$(obj).css("background-color", "#FFFFFF")
				
			}
		} */
		
		function getUrl(){
			
			alert('${basePath}');
			alert('${url}');
		}
	
		function setFinish(projectId,tableId) {
			
			var rows = table.rows.length;
			
			var cells = table.rows.item(0).cells.length;
			var flag = true;
			for (var i = 0; i < rows; i++) {
				var cellValue = [];
				for (var j = 0; j < cells; j++) {
					valuej = table.rows.item(i).cells.item(j).childNodes[0].value;
					if(valuej == "" || valuej == null){
						flag = false;
					}
					
				}
				
			}
			
			if(flag){
				$.ajax({
					url : "${base}/table/changeStatuFinish",
					data : {
						"projectId" : projectId,
						"tableId" : tableId
					},
					type : "POST",
					success : function() {
						location.reload();
					},
					async : true,
					cache : false
				}); 
			}else{
				alert("该表格尚未完成，不能设置为完成");
			}
		 	
		}
		
		function collection(userId,tableId) {
			
			
		 	$.ajax({
				url : "${base}/user/collection",
				data : {
					"userId" : userId,
					"tableId" : tableId
				},
				type : "POST",
				success : function() {
					location.reload();
				},
				async : true,
				cache : false
			}); 
		}
		
		function deleteCollection(userId,tableId) {
			
			
		 	$.ajax({
				url : "${base}/user/deleteCollection",
				data : {
					"userId" : userId,
					"tableId" : tableId
				},
				type : "POST",
				success : function() {
					location.reload();
				},
				async : true,
				cache : false
			}); 
		}
	

	function dropDown(obj) {
		
	    var index=obj.selectedIndex; //序号，取当前选中选项的序号
	  
	    var ccc=obj.options[index].className;
	     obj.style.background=ccc;
		   
		var map = {};
		

		var rows = table.rows.length;
		
		var cells = table.rows.item(0).cells.length;
		
		for (var i = 0; i < rows; i++) {
			var cellValue = [];
			for (var j = 0; j < cells; j++) {
				valuej = table.rows.item(i).cells.item(j).childNodes[0].value;
				
				cellValue[j] = valuej;
			}
			map[i.toString()] = cellValue;
		}
		var json = JSON.stringify(map);
		var params = JSON.stringify(json);
		
		var tableName = $("#tableName").html();
		
		console.log(tableName);
		$.ajax({
			url : "${base}/excel/save",
			data : {
				"json" : params,
				"tableName" : tableName
			},
			type : "POST",
			success : function() {
				
			},
			async : true,
			cache : false
		});
	}
	function textbox() {
		
		
		var map = {};

		var rows = table.rows.length;
		
		var cells = table.rows.item(0).cells.length;
		
		for (var i = 0; i < rows; i++) {
			var cellValue = [];
			for (var j = 0; j < cells; j++) {
				
				var valuej = table.rows.item(i).cells.item(j);
			
				cellValue[j] = valuej.childNodes[0].value;
				 
			}
			
			map[i.toString()] = cellValue;
		}
		var json = JSON.stringify(map);
		var params = JSON.stringify(json);
		
		var tableName = $("#tableName").html();
		
		console.log(tableName);
		$.ajax({
			url : "${base}/excel/save",
			data : {
				"json" : params,
				"tableName" : tableName
			},
			type : "POST",
			success : function() {
				
			},
			async : true,
			cache : false
		}); 
	}
	function addRow() {
		var tr = document.createElement('tr');
		tr.className = "tr";
		var tbody = document.getElementById("tbody");
		var rows = table.rows.length;
		var cells = table.rows.item(0).cells.length;
		tbody.appendChild(tr);
		for (var i = 0; i < cells; i++) {
			var inputi = document.createElement('input');
			inputi.style.border = "none";
			inputi.style.height = "35px";
			inputi.style.width = "100%";
			inputi.style.font.size = "10px";
			var tdi = document.createElement('td');
			tdi.appendChild(inputi);
			tdi.className = "td";
			tdi.style.height = "46px";
			tdi.style.width = " 5%";
			tr.appendChild(tdi);
		}
	}
	
	function AddRow() {
		var colEditor = prompt("请输入该行编辑人","");
		var lastRow = table.rows[table.rows.length - 1];
		var newRow = lastRow.cloneNode(true);
		alert(newRow);
		table.tBodies[0].appendChild(newRow);
		
		
		
		textbox();
		return newRow;

	}
	
	
	function addCell() {
		var colName = prompt("请输入该列列名","");
		var tableId = ${table.id};
		$(".th")
				.append(
						'<td class="td" onclick="get(this)"  style="width: 120px;height:auto;border:1px solid #88ADA6;" ><input '
										+'type="button"  readonly="readonly" '
										+'style="border: none; height: 35px; font-size: 10px; width: 100%; word-wrap: break-word;"' 
										+' value="'+colName+'"></td>');
		$(".tr")
				.append(
						'<td class="td" onclick="get(this)"  style="auto;border:1px solid #88ADA6;" ><input '
										+'type="text" onchange="textbox()"  editor="" '
										+'style="border: none; height: 35px; font-size: 10px; width: 100%; word-wrap: break-word;"' 
										+' value=""></td>');
		
		textbox();
		 $.ajax({
			url : "${base}/table/addTableCol",
			data : {
				"tableId" : tableId,
				"colName" : colName
			},
			type : "POST",
			success : function() {
				
			},
			async : true,
			cache : false
		});  
	}
	
	function addEditorRow() {
		 var rowEditor = $("#rowEditorName").val(); 
		
		 var projectId = ${project.id};
		 var tableId = ${table.id};
		var lastRow = table.rows[table.rows.length - 1];
		var newRow = lastRow.cloneNode(true);
		var num = newRow.getElementsByTagName("td").length;
		for(var i = 0; i<num;i++){
			$(newRow.children[i].children[0]).attr("editor",rowEditor);
		}
	
		table.tBodies[0].appendChild(newRow);
		
		 $.ajax({
				url : "${base}/table/addTableRow",
				data : {
					"tableId" : tableId,
					"rowEditor" : rowEditor,
					"projectId" : projectId
				},
				type : "POST",
				success : function() {
					
				},
				async : true,
				cache : false
			});
		
		textbox();
		return newRow; 

	}
	
	
	function addEditorCol() {
		
		var colName = $("#colName").val();
		var colEditor = $("#memberName1").val();
		var tableId = ${table.id};
		$(".th")
				.append(
						'<td class="td" onclick="get(this)"  style="width: 120px;height:auto;border:1px solid #88ADA6;" ><input '
										+'type="button"  readonly="readonly" '
										+'style="border: none; height: 35px; font-size: 10px; width: 100%; word-wrap: break-word;"' 
										+' value="'+colName+'"></td>');
		for(var i=0;i<table.rows.length-1;i++){
		var editor = $($(".tr"+i)[0].children[0].children[0]).attr("editor");
		$(".tr"+i)
				.append(
						'<td class="td" onclick="get(this)"  style="auto;border:1px solid #88ADA6;" ><input '
										+'type="text" onchange="textbox()"  editor="'+editor+'" colEditor="'+ colEditor+'" '
										+'style="border: none; height: 35px; font-size: 10px; width: 100%; word-wrap: break-word;"' 
										+' value=""></td>');
		}
		
		
		
		  $.ajax({
			url : "${base}/table/addTableCol",
			data : {
				"tableId" : tableId,
				"colName" : colName,
				"colEditor":colEditor
			},
			type : "POST",
			success : function() {
				
			},
			async : true,
			cache : false
		}); 
		  textbox();
	}
	
	
	
	
	
	var flag=true;
	var s = null;
	var e = null;
	
	var el = null;
	function get(obj){
		el=obj;
		if(flag){
			s=obj;
			$('.td').css("background-color", "#FFFFFF");
			$('.td1').css("background-color", "#9BCD9B");
			$(obj).css("background-color", "#3399FF");
			flag=false;
		}else{
			e=obj;
			$('.td').css("background-color", "#FFFFFF");
			$('.td1').css("background-color", "#9BCD9B");
			$(obj).css("background-color", "#3399FF");
			
			flag=true;
		}
	}
	
	
	function hb() {
		
		var start_tr=s.parentNode;
		var start_td=s;
		var start_r=s.parentNode.rowIndex;
		var start_c=s.cellIndex;
		
		var end_tr=e.parentNode;
		var end_td=e;
		var end_r=e.parentNode.rowIndex;
		var end_c=e.cellIndex;
		var tableId = ${table.id};	
	
		if(start_r==end_r){
		table.rows[start_r].cells[start_c].colSpan = (end_c-start_c)+table.rows[end_r].cells[end_c].colSpan; 
			var start_clospan=table.rows[start_r].cells[start_c].colSpan;
			
			for(var i=(start_c+start_clospan);i>start_c+1;i--){
						
					/* table.rows[end_r].cells[i].innerHTML="";
					 table.rows[end_r].deleteCell(i);  */
					 $(table.rows[end_r].cells[i-1]).hide(); 
					 
					 /* $("#id").show(); */
					
			 	
			}
			/* var s_colspan = s.colSpan;
			
			var e_colspan = e.colSpan;
			alert(s_colspan);
			alert(e_colspan); */
			var colspan = s.colSpan;
			$(s).css("width", parseInt(colspan*120)+"px");
		/* 	alert("start_clospan="+start_clospan+",colspan="+colspan);
			 */
			
			 $.ajax({
				url : "${base}/table/mergeBoxCol",
				data : {
					"colNum" : start_c,
					"rowNum" : start_r,
					"colspan" : colspan,
					"tableId" : tableId
				},
				type : "POST",
				success : function() {
					
				},
				async : true,
				cache : false
			});   
			
			
		}else{
			table.rows[start_r].cells[start_c].rowSpan = table.rows[end_r].cells[end_c].rowSpan+(end_r-start_r);
			var rowspan = $(s).attr("rowspan");
			for(var i=end_r;i>start_r;i--){
				
				$(table.rows[i].cells[start_c]).hide();
				/* table.rows[i].cells[start_c].innerHTML="";
				 table.rows[i].deleteCell(end_c);   */
			}
			
			 $.ajax({
					url : "${base}/table/addMergeBoxRow",
					data : {
						"colNum" : start_c,
						"rowNum" : start_r,
						"rowspan" : rowspan,
						"tableId" : tableId
					},
					type : "POST",
					success : function() {
						
					},
					async : true,
					cache : false
				});
		
			
		/* 	flag=true; */
		}
		
		$('.td').css("background-color", "#FFFFFF");	
	
		s=null;
		e=null;
	
	}	
	
	
	function resolution(){
		
		var el_colspan = null;
		var el_rowspan = null;
		var el_r = null;
		var el_c = null;
		if(el.tagName == 'INPUT'){
			el_colspan = $(el.parentNode).attr("colspan");
			el_rowspan = $(el.parentNode).attr("rowspan");
			el_r = el.parentNode.parentNode.rowIndex;
			el_c = el.parentNode.cellIndex;
		}else{
			 
		el_colspan=$(el).attr("colspan");
		
		
		el_rowspan=$(el).attr("rowspan");
		el_r = el.parentNode.rowIndex;
		el_c = el.cellIndex;
		}
	
		var tableId = ${table.id};	
		if(el_colspan>1){
			
			for(var i=el_c;i<(el_c+el_colspan)-1;i++){
				
				 $(table.rows[el_r].cells[i+1]).show(); 
				 $(table.rows[el_r].cells[i+1]).css("width","120px"); 
				
			}
			alert(table.rows[el_r].cells[el_c]);
			table.rows[el_r].cells[el_c].colSpan = 1;
			
			$(table.rows[el_r].cells[el_c]).css("width","120px");
			 $.ajax({
					url : "${base}/table/deleteMergeCol",
					data : {
						"colNum" : el_c,
						"rowNum" : el_r,
						"tableId" : tableId
					},
					type : "POST",
					success : function() {
						
					},
					async : true,
					cache : false
				});  
			
		}else if(el_rowspan>1){
			
			table.rows[el_r].cells[el_c].rowSpan = 1;
			var max = parseInt(el_r)+parseInt(el_rowspan)-1;
			
			for(var i=el_r;i<max;i++){
				
				$(table.rows[i+1].cells[el_c]).show();
				/* table.rows[i].cells[start_c].innerHTML="";
				 table.rows[i].deleteCell(end_c);   */
			}
			 $.ajax({
					url : "${base}/table/deleteMergeRow",
					data : {
						"colNum" : el_c,
						"rowNum" : el_r,
						"tableId" : tableId
					},
					type : "POST",
					success : function() {
						
					},
					async : true,
					cache : false
				}); 
		}else{
			alert("该单元格无法再拆分");
		}
	}
	
	/* alan_18.2.6_点击复制路径 */
	function urlCopy(){  
        var e=document.getElementById("copy-num");//对象是copy-num1  
        e.select(); //选择对象  
        document.execCommand("Copy"); //执行浏览器复制命令  
        alert("复制成功");  
    }  


/* 	$(".td").bind("mouseover", function() {
		$(this).css("background-color", "#EEA236");
	})
	$(".td").bind("mouseout", function() {
		$(this).css("background-color", "#ffffff"); 
	})*/
</script>

</html>
